<{include file=$module.'/header.php'}>

<div class="page goods-add" id="page-goods-post">
	<header class="bar bar-nav common-bar-nav">
		<a class="pull-left external" href="/<{$module}>/my/index"><i class="fa fa-arrow-left"></i></a>
		<h1 class="title">提交<{$tit}></h1>
		<a href="javascript:;" onclick="location.reload();" class="pull-right">刷新</a>
	</header>
	<div class="btn-submit">
		<a href="javascript:;" class="button button-big button-fill button-danger">提交</a>
	</div>
	<div class="content">


		<div class="tabs">
			<!-- 设备报修 -->
			<div id="device-add" class="tab active">
				<form id="form" >
				<input type="hidden" name="id" value="<{$info.id}>" />
				<input type="hidden" name="do" value="<{$action}>" />
	
				<div class="list-block">
					<ul>
						<li>
							<a class="item-link item-content">
								<div class="item-inner">
									<div class="item-title label">科室</div>
									<div class="item-input">
										<span id="local-zone"><{$zone['name']}></span>
										<input id="data-zone" type="hidden" name="zone_id" value="<{$zone.id}>"/>
									</div>
								</div>
							</a>
						</li>
					</ul>
				</div>
				
				<div class="list-block">
					<ul>
						<li>
							<a class="item-link item-content open-popup" data-popup=".popup-life-cate">
								<div class="item-inner">
									<div class="item-title label">类别</div>
									<div class="item-input">
										<span id="local-cate">请选择类别</span>
										<input id="data-cate" type="hidden" name="cate_id" value=""/>
									</div>
								</div>
							</a>
						</li>
					</ul>
				</div>
				
				
				<div class="list-block">
					<ul>
						<li class="hide" id="bx_shifu">
							<a class="item-link item-content">
								<div class="item-inner">
									<div class="item-title label">师傅</div>
									<div class="item-input">
										<span id="local-shifu">请选择师傅</span>
										<input id="data-shifu" type="hidden" name="shifu_id" value="0"/>
										<!-- <input id="data-zhiban" type="hidden" name="is_zhiban" value="0"/> -->
									</div>
								</div>
							</a>
						</li>
						<li>
							<div class="item-content">
								<div class="item-inner">
									<div class="item-title ">位置</div>
									<div class="item-input">
										<input type="text" name="local" value="<{$info.local}>" placeholder="请输入位置">
									</div>
								</div>
							</div>
						</li>

					</ul>
				</div>
				
				<div class="list-block">
					<ul>
						<li>
							<div class="item-content">
								<div class="item-inner">
									<div class="item-title ">标题</div>
									<div class="item-input">
										<input type="text" name="title" value="<{$info.title}>" placeholder="请输入标题">
									</div>
								</div>
							</div>
						</li>
					</ul>
				</div>

				<div class="list-block m-b-0 other-info">
					<ul>
						<li class="align-top">
							<div class="item-content">
								<div class="item-inner">
									<div class="item-input">
										<textarea id="data-details" name="intro" placeholder="请输入描述"><{$info.intro}></textarea>
									</div>
									<a id="post-voice" data-id="0" class="post-voice start"></a>
								</div>
							</div>
						</li>
					</ul>
				</div>
				
				<!-- <{if !$is_wx}>
				<div class="list-block">
					<ul>
						<li>
							<div class="item-content">
								<div class="item-inner">
									<div class="item-title ">录音</div>
									<div class="item-after">
										<audio class="recPlay"></audio>
									</div>
								</div>
							</div>
						</li>
					</ul>
				</div>
				<{/if}> -->
				
				<div class="content-block-title">图片</div>
				<div class="image-container muti-upload">
					<ul id="upload-list" class="upload-list p-b-1">
						<li class="list-button"><input id="upload-select" type="file" accept="image/*" multiple><i class="fa fa-plus"></i></li>
						<{if $photos}>
						<{foreach $photos as $val}>
						<li><img src='<{$val}>'><a href='javascript:;' class='remove'>删除</a><input type='hidden' name='photo[]' value='<{$val}>'></li>
						<{/foreach}>
						<{/if}>
					</ul>
				</div>

				</form>
			</div>
			
		</div>

		<div class="ui-footspace"></div>
	</div>
</div>

<!-- 一级区域 -->
<div class="popup popup-life-area uc-post-lifecate">
	<header class="bar bar-nav">
		<button class="button button-link pull-right close-popup">关闭</button>
		<h1 class="title">选择区域</h1>
	</header>	
	<div class="content">
		<div class="list-block m-a-0 list-block-first">
			<ul id="uc-post-area">
			 	<{foreach $areas as $k => $v}>
				<li>
					<a class="item-content" data-no="area" data-id="<{$v.id}>" data-name="<{$v.name}>">
						<div class="item-inner"> <{$v.name}></div>
					</a>
				</li>
				<{/foreach}>
			</ul>
		</div>
	</div>
</div>
<div class="popup popup-life-area1 uc-post-lifecate">
	<header class="bar bar-nav">
		<button class="button button-link pull-right close-popup">关闭</button>
		<h1 class="title">选择区域</h1>
	</header>	
	<div class="content">
		<div class="list-block m-a-0 list-block-first">
			<ul id="uc-post-area1">
			 	
			</ul>
		</div>
	</div>
</div>
<!-- 一级分类 -->
<div class="popup popup-life-cate uc-post-lifecate">
	<header class="bar bar-nav">
		<button class="button button-link pull-right close-popup">关闭</button>
		<h1 class="title">选择分类</h1>
	</header>	
	<div class="content">
		<div class="list-block m-a-0 list-block-first">
			<ul id="uc-post-cate">
			 	<{foreach $cates as $k => $v}>
				<li>
					<a class="item-content" data-no="cate" data-id="<{$v.id}>" data-name="<{$v.name}>">
						<div class="item-inner"> <{$v.name}></div>
					</a>
				</li>
				<{/foreach}>
			</ul>
		</div>
	</div>
</div>
<div class="popup popup-life-cate1 uc-post-lifecate">
	<header class="bar bar-nav">
		<button class="button button-link pull-right close-popup">关闭</button>
		<h1 class="title">选择分类</h1>
	</header>	
	<div class="content">
		<div class="list-block m-a-0 list-block-first">
			<ul id="uc-post-cate1">
			 	
			</ul>
		</div>
	</div>
</div>
<!-- 一级地点 -->
<div class="popup popup-life-zone uc-post-lifecate">
	<header class="bar bar-nav">
		<button class="button button-link pull-right close-popup">关闭</button>
		<h1 class="title">选择地点</h1>
	</header>	
	<div class="content">
		<div class="list-block m-a-0 list-block-first">
			<ul id="uc-post-zone">
			 	<{foreach $zones as $k => $v}>
				<li>
					<a class="item-content" data-no="zone" data-id="<{$v.id}>" data-name="<{$v.name}>">
						<div class="item-inner"> <{$v.name}></div>
					</a>
				</li>
				<{/foreach}>
			</ul>
		</div>
	</div>
</div>
<div class="popup popup-life-zone1 uc-post-lifecate">
	<header class="bar bar-nav">
		<button class="button button-link pull-right close-popup">关闭</button>
		<h1 class="title">选择地点</h1>
	</header>	
	<div class="content">
		<div class="list-block m-a-0 list-block-first">
			<ul id="uc-post-zone1">
			 	
			</ul>
		</div>
	</div>
</div>
<script>
$(function(){
	// 一级分类
	$(document).on("click","#uc-post-area a,#uc-post-cate a,#uc-post-zone a",function(e){
		var data_no = $(this).attr("data-no");
		var data_id = $(this).attr("data-id");
		var data_name = $(this).attr("data-name");
		$.post("/<{$routeUrl}>/ajax_child",{id:data_id,type:data_no},function(result){
			if(result.length > 1){
				$("#uc-post-"+data_no+"1").html(result);
				// $("#uc-post-"+data_no).hide();
				$.closeModal(".popup-life-"+data_no+"");
				$.popup(".popup-life-"+data_no+"1");
			}
		});
	});

	// 二级分类
	$(document).on("click","#uc-post-area1 a",function(e){
		var data_no = $(this).attr("data-no");
		var data_id = $(this).attr("data-id");
		var data_name = $(this).attr("data-name");
		$("#data-"+data_no).val(data_id);
		$("#local-"+data_no).html(data_name);

		$.closeModal();
	});

	// 二级分类
	$(document).on("click","#uc-post-cate1 a",function(e){

		// var area = $.trim($('[name="area_id"]').val());
		// if(!area) {
		// 	$.toast('区域不能为空');
		// 	return false;
		// }
		// var cate = $.trim($('[name="cate_id"]').val());
		// if(!cate) {
		// 	$.toast('分类不能为空');
		// 	return false;
		// }
		
		var data_no = $(this).attr("data-no");
		var data_id = $(this).attr("data-id");
		var data_name = $(this).attr("data-name");
		$("#data-"+data_no).val(data_id);
		$("#local-"+data_no).html(data_name);

		var area_id = $("#data-area").val();
		var cate_id = $("#data-cate").val();
		var zone_id = $("#data-zone").val();

		$.post("/<{$routeUrl}>/ajax_shifu",{area_id:area_id,cate_id:cate_id,zone_id:zone_id},function(result){
			if(result.code == 1){
				$("#data-shifu").val(result.shifu_id);
				$("#local-shifu").html(result.msg);
				$("#bx_shifu").removeClass('hide');
				// $.closeModal(".popup-life-zone");
				return false;
			}
			// if(result.length > 100){
			// 	$("#uc-post-shifu").html(result);
			// 	// $("#local-city").html(name);
			// 	// $.closeModal(".popup-life-zone");
			// 	$.popup(".popup-life-shifu");
			// }else{
			// 	$.closeModal(".popup-life-zone");
			// }
		});

		$.closeModal();
	});
});
</script>

<script src="/static/app/js/upload.js"></script>
<script>

	// //将base64转换为blob
    // dataURLtoBlob: function(dataurl) { 
    //     var arr = dataurl.split(','),
    //         mime = arr[0].match(/:(.*?);/)[1],
    //         bstr = atob(arr[1]),
    //         n = bstr.length,
    //         u8arr = new Uint8Array(n);
    //     while (n--) {
    //         u8arr[n] = bstr.charCodeAt(n);
    //     }
    //     return new Blob([u8arr], { type: mime });
    // },
    // //将blob转换为file
    // blobToFile: function(theBlob, fileName){
    //    theBlob.lastModifiedDate = new Date();
    //    theBlob.name = fileName;
    //    return theBlob;
    // },
    


$(function(){
	//提交
	$(document).on('click', '.goods-add .button-danger', function(){
		var $button = $(this);
		if($button.hasClass('disabled')) {
			return false;
		}
		// var area = $.trim($('[name="area_id"]').val());
		// if(!area) {
		// 	$.toast('区域不能为空');
		// 	return false;
		// }
		var cate = $.trim($('[name="cate_id"]').val());
		if(!cate) {
			$.toast('分类不能为空');
			return false;
		}
		// var zone = $.trim($('[name="zone_id"]').val());
		// if(!zone) {
		// 	$.toast('地点不能为空');
		// 	return false;
		// }
		var local = $.trim($('[name="local"]').val());
		if(!local) {
			$.toast('位置不能为空');
			return false;
		}
		var title = $.trim($('[name="title"]').val());
		if(!title) {
			$.toast('标题不能为空');
			return false;
		}
		
		// e.preventDefault();
		var params = $('#form').serializeArray();
		$button.addClass('disabled');
		$.post("/<{$routeUrl}>/<{$action}>", params, function(response){
			if(response.code == 0){
				$button.removeClass('disabled');
				$.toast(response.msg);
				return false;
			}
			if(response.code == 1){
				$.toast(response.msg, response.url);
			}
		});
	});

	//上传图片
	$(document).on('change', '#upload-select', function(e){ 
		for(var i=0;i<this.files.length;i++){
			// console.log(this.files[i]);

			lhj(this.files[i], {
			    width:1000,
			    height:1000,
			    // 压缩成功
			    done: function (results) {
					postdata = {
						base64: results.base64,
						name: results.origin.name,
						type: results.origin.type,
						size: results.origin.size,
					};
					$.post('/<{$module}>/api/upload', postdata, function(response){
						if(response.code == 0){
							error("上传失败");
							return false;
						}
						if(response.code == 1){
							txt = "<li><img src='" + results.base64+"'><a href='javascript:;' class='remove'>删除</a><input type='hidden' name='photo[]' value='"+ response.data +"'></li>";
			    			$("#upload-list").append(txt);
						}
					});
			    }
			});
		}
	});
	//删除图片
	$(document).on('click', '.remove', function(e){ 
	 	var file_id = $(this).parent().find("input").val();
		$.post('/<{$module}>/api/remove', { file_id: file_id }, function(data){ 
		});
	 	$(this).parent().remove();
	});

	// 手机搜索
	$(document).on("click",".icon-search",function(e){
		var tel = $.trim($('[name="tel"]').val());
		if(!tel) {
			$.toast('手机号不能为空');
			return false;
		}
		$.post("/<{$module}>/api/ajaxtel",{tel:tel},function(response){
			if(response.code == 0){
				$.toast('手机号不存在');
				return false;
			}
			if(response.code == 1){
				$.toast('客户已找到');
				$("#data-realname").val(response.realname);
				$("#data-company").val(response.company);
				$("#data-username").val(response.username);
			}
		});
	});

	
	$.init();
});
</script>
<{include file=$module.'/footer.php'}>